﻿addLoadEvent(bindDefaultsetEvent);
addLoadEvent(bindLoginEvent);
addLoadEvent(bindRegisterEvent);
var ASPNETFORM={autoString:"ctl00$contentbody$"}

function bindRegisterEvent(){
    var registerForm=$fm("aspnetForm");
    var registerId=$("register");
    if(registerForm==null||registerId==null){
        return;
    }
    initRegister.call(registerForm);
}


function bindDefaultsetEvent(){
    var defaultSetForm=$fm("aspnetForm");
    var defaultSetId=$("defaultset");
    if(defaultSetForm==null||defaultSetId==null){
        return;
    }
    initDefaultSet.call(defaultSetForm);
}

function bindLoginEvent(){
    var loginForm=$fm("aspnetForm");
    var loginId=$("loginpane");
    if(loginForm==null||loginId==null){
        return;
    }
    initLogin.call(loginForm);
}
function initLogin(){
    var padN=ASPNETFORM.autoString+"login$";
    this.InputText=[
    this[padN+"nameTb"],
    this[padN+"pwdTb"]
    ]
    bindMulitObjectEvent.call(this.InputText,["onfocus", FocusInputText],["onblur", BlurInputText],["onchange", ChangeInputText]);
    this.onsubmit=submitLogin;
}

function initDefaultSet(){
    var padN=ASPNETFORM.autoString;
    this.InputText=[
    this[padN+"titleTb"],
    this[padN+"widthTb"],
    this[padN+"heightTb"],
    this[padN+"bgSoundTb"]
    ]
    bindMulitObjectEvent.call(this.InputText,["onfocus", FocusInputText],["onblur", BlurInputText],["onchange", ChangeInputText]);
    this.onsubmit=submitDefaultSet;
}

function initRegister(){
     var padN=ASPNETFORM.autoString+"reg$";
     this.InputText=[
            this[padN+"userNameTb"],
            this[padN+"pwdTb"],
            this[padN+"repwdTb"],
            this[padN+"qqTb"],
            this[padN+"telTb"],
            this[padN+"emailTb"],
            this[padN+"addrTb"],
            this[padN+"emailTb"],
      ]
     bindMulitObjectEvent.call(this.InputText,["onfocus", FocusInputText],["onblur", BlurInputText],["onchange", ChangeInputText]);
     this.onsubmit=submitRegister;
}

function submitLogin(){
    var padN=ASPNETFORM.autoString+"login$";
    if(!CheckLength.call(this[padN+"nameTb"],3,15)){
        alert("用户名为3-15位");
        return false;
    }
    if(!CheckLength.call(this[padN+"pwdTb"],3,15)){
        alert("密码太短");
        return false;
    }
    return true;
}


function submitDefaultSet(){
    var padN=ASPNETFORM.autoString;
    
    if(!CheckLength.call(this[padN+"titleTb"],3,15)){
        alert("杂志名称在3-15个字之间");
        return false;
    }
    if(!CheckNaN.call(this[padN+"widthTb"])||!CheckNaN.call(this[padN+"heightTb"])){
        alert("宽度/高度必须为数字");
        return false;
    }
}

function submitRegister(){
    var padN=ASPNETFORM.autoString+"reg$";
    if(!CheckLength.call(this[padN+"userNameTb"],3,15)){
        alert("用户名请指定在3-15个字");
        return false;
    }
    if(!CheckLength.call(this[padN+"pwdTb"],6,20)){
        alert("密码必须至少6位");
        return false;
    }
    if(!Equals.call(this[padN+"pwdTb"],this[padN+"repwdTb"])){
        alert("两次密码不相同");
        return false;
    }
    if(!CheckLength.call(this[padN+"telTb"],11,11)){
        alert("手机号码必须是11位");
        return false;
    }
    if(!CheckMail.call(this[padN+"emailTb"])){
        alert("邮箱格式不正确");
        return false;
    }
}

function FocusInputText(){
    this.className="focusinput";
}
function BlurInputText(){
    this.className="input";
}
//暂时不做即时;
function ChangeInputText(){
   /* var padN="ctl00$contentbody$";
    
    switch(this.name){
        case padN+"titleTb" :
            CheckLength.call(this,3,15);
            break;
        case padN+"widthTb":
        case padN+"heightTb":
            CheckNaN.call(this);
            break;
        default:
            break;
    }*/
}

function CheckMail(){
    if(!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(this.value)){
        return false;
    }
    return true;
 }
function CheckLength(min,max){
    if(this.value.length < min || this.value.length > max){
        this.focus();
        return false;
    }
    return true;
}
function CheckNaN(){
    if(isNaN(this.value)){
        return false;
    }
    return true
}
function Equals(obj){
    return (this.value==obj.value);
}

function bindMulitObjectEvent(){
    for(var i=0;i<this.length;i++){
        bindObjectMulitEvent.apply(this[i],arguments);
    }
}
function bindObjectMulitEvent(){
    for(var i=0;i<arguments.length;i++){
        this[arguments[i][0]]=arguments[i][1];
    }
}